package com.qingding.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.RadioGroup;

import com.qingding.R;

import com.qingding.view.RadioButtonTools;

import static com.qingding.R.drawable.radio_button;
import static com.qingding.utils.Some_Public_Data.TYPE;

public class Types extends AppCompatActivity {
    private RadioGroup radioGroup;
    private Intent result;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_types);
        //单选键
        int[] radio_buttons={R.id.thing,R.id.day_life,R.id.love,
                            R.id.birthday,R.id.learn,R.id.work
        };
        //图片
        int[] drawables={R.drawable.things,R.drawable.everyday,R.drawable.love,
                R.drawable.birthday,R.drawable.learn,R.drawable.checked,
        };
        RadioButtonTools.changeSize(radio_buttons,drawables,this, radio_button);
        radioGroup=(RadioGroup) findViewById(R.id.type_list);
        result=new Intent();
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                result.putExtra("type",getTypeName(checkedId));
                setResult(TYPE,result);
            }
        });

    }

    public void finish(View view) {
        this.finish();
    }

    @Override
    protected void onStop() {
        super.onStop();
        this.finish();
    }
    private String getTypeName(int id) {
        switch (id) {
            case R.id.thing: {
                return "thing";
            }
            case R.id.day_life: {
                return "day_life";
            }
            case R.id.love: {
                return "love";
            }
            case R.id.birthday: {
                return "birthday";
            }
            case R.id.learn: {
                return "learn";
            }
            case R.id.work: {
                return "work";
            }
            default:
                return "nothing";
        }
    }
}
